xquery version "1.0";

declare namespace util="http://exist-db.org/xquery/util";
declare namespace dc="http://purl.org/dc/elements/1.1/";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace session="http://exist-db.org/xquery/session";

declare option exist:serialize "method=xhtml media-type=text/xml";

element { "tracks" }{
	fn:subsequence(
	for $track in doc("Test1/Tracks.xml")//track
	let $artistId := request:get-parameter("artistId", ())
	
	where $track/artist_id/text() = $artistId
	order by $track/rating-count descending
	return $track,
	1, xs:integer(request:get-parameter("count", ())))
}
			
